package koction.aopcommon;
import java.util.List;

import javax.annotation.Resource;


import koction.model.rankService.RankService;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
//@Component  //context:component scan 을 통해 bean 생성, 
// 아니면 xml에서 bean을 명시하면 된다. 

@Component 
@Aspect
public class SearchAspect {
	@Resource(name="rankServiceImpl")
	private RankService rankService;
	private Log log=LogFactory.getLog(getClass());
	@Around("execution(* koction.model.product.*Service.search*(..))")
	public Object productNameLogging(ProceedingJoinPoint point) throws Throwable{		
		String sName = point.getTarget().getClass().getName();
		
		String mn=point.getSignature().getName();
		Object[] params = point.getArgs(); //0 : 갤럭시 1 : name
		Object retValue = null;
		try
		{
			retValue = point.proceed(); //ProductVO
			log.info("검색어로그~~"+retValue);
			
			
		}
		finally
		{
		 if(retValue instanceof List && ((List) retValue).size()>0)
			System.out.println(retValue instanceof List);
			rankService.insertKeyword(params[0].toString());
		}
		
		return retValue;
	}
}
